/** @file SubLoader.qml
@brief The Qt-Complex loader used for sub-elements.

The subloader is used to manage compound objects. For normal objects use
the Loader instead.

@authorname \n
@licenseversion \n
@actualversion - @dateupdate

@licensenote
*/

import QtQuick 1.0

// The loader element surrounded by its item
Item {
    id: itemLoader

    // Loader properties to be assigned in the program
    property string obj: ""     // Object to load
    property string urlObj:  "" // Object loaded from a http url
    property string theme: ""   // Theme name
    // The used properties depends by the object type.
    property string obj_string: ""  // Generic string assigned to fields, buttons, etc.
    property string obj_message: ""  // Generic message assigne to text
    property string obj_icon:  ""   // Generic Icon Name
    // Geometry dependent properties (default values are overriddend by the applicaiton)
    property int switchHeigth: 45               // Height of every object
    property int fontPoints: 10                 // Base text font size in points
    property int fontSwitches: 8                // Switch text description font size in points
    property int fieldSpacing: 5                // Distance between fields
    // The signals connected with the object types
    signal clicked
    signal clickedCoord(int x, int y)

    Loader {
        id:objSubLoad

        // Set of inline functions returning the requested property
        function getString() { return itemLoader.obj_string; }
        function getMessage() { return itemLoader.obj_message; }
        function getWidth() { return itemLoader.width; }
        function getHeight() { return itemLoader.height; }
        function getIcon() { return itemLoader.obj_icon; }
        function getFontPoints() { return itemLoader.fontPoints; }
        function getFontSwitches() { return itemLoader.fontSwitches; }
        function getFieldSpacing() { return itemLoader.fieldSpacing; }
        function getTheme() { return itemLoader.theme; }
        function objDestroy() { source = ""; }

        // The object source definition: can be a server URL or a local file.
        source: (itemLoader.obj == "") ? itemLoader.urlObj: itemLoader.obj + ".qml";
    }

    // The connections to the possible signals returned by the objects
    Connections {
        target: objSubLoad.item
        // The ignoerUnknownSignals is set to true because not all the loadable objects
        // manages the same signals.
        ignoreUnknownSignals: true
        // Signal returned by buttons and objects that manages buttonclick()
        onObjClicked: { itemLoader.clicked(); }
        onObjClickCoord: { itemLoader.clickedCoord(x, y) }
    }
}
